package com.main.mq;

import com.main.util.MailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;

//@Service
public class MessageServiceActivemq {
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;
    @Autowired
    private MailUtils mailUtils;

    public void sendMessage(String email, String code) {
        System.out.println("-待发送短信的订单已纳入消息处理队列，id:" + email + "--" + code);
        mailUtils.sendMail(email, code);
        jmsMessagingTemplate.convertAndSend("user.queue.code"," mailUtils.sendMail(email, code)");//
    }

    public String doMessage() {
//        String id = jmsMessagingTemplate.receiveAndConvert(String.class);
        String id = jmsMessagingTemplate.receiveAndConvert("order.queue.id", String.class);
        System.out.println("-已完成短信发送业务id:" + id);
        return id;
    }
}
